package servce

import (
	"video/global"
	"video/internal/model/dao"
	"video/internal/request"
)

func AddVideo(req request.VideoReq) error {
	video := dao.Video{
		Title:    req.Title,
		Video:    req.Video,
		Sex:      req.Sex,
		Age:      req.Age,
		IsStatus: req.IsStatus,
	}
	err := global.DB.Create(&video).Error
	if err != nil {
		return err
	}
	return nil
}

func VideoList(page int, pageSize int) ([]dao.Video, error) {
	var video []dao.Video
	err := global.DB.Offset((pageSize - 1) * page).Limit(page).Find(&video).Error
	if err != nil {
		return nil, nil
	}
	return video, err
}
func VideoShow(id int) (dao.Video, error) {
	var video dao.Video
	err := global.DB.Where("id = ?", id).First(&video).Error
	if err != nil {
		return dao.Video{}, err
	}
	return video, nil
}
func UserShow(id int) (dao.Video, error) {
	var video dao.Video
	err := global.DB.Where("id = ?", id).First(&video).Error
	if err != nil {
		return dao.Video{}, err
	}
	return video, nil
}
